package com.logindemo.controller;


import com.logindemo.domain.Account;
import com.logindemo.domain.ResponseResult;
import com.logindemo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    @GetMapping("/test")
    public String test(){
        return "test";
    }


    @PostMapping("/login")
    public ResponseResult login(@RequestBody Account account){
        HashMap<String, String> login = accountService.login(account);
        return ResponseResult.builder().msg("登录成功").data(login).build();
    }

    @PostMapping("/logout")
    public ResponseResult logout(){
        Boolean logout = accountService.logout();
        return ResponseResult.builder().msg("退出成功").data(logout).build();
    }

    @PostMapping("/register")
    public ResponseResult register(@RequestBody Account account){
        Account register = accountService.register(account);
        return ResponseResult.builder().msg("注册成功").data(register).build();
    }
}
